const express = require('express');
const path = require('path');
const app = express();

// Routes
app.get(`/`, (req, res) => {
  res.sendFile(path.join(__dirname, 'index.html'));
});

app.get('/user', (req, res) => {
  res.json({
    code: 0,
    message: "成功"
  });
});

// app.get('/user/:id', (req, res) => {
//   const id = req.params.id;
//   res.send({
//     id: id,
//     title: 'serverless framework',
//     link: 'https://serverless.com',
//   });
// });

// Error handler
// app.use(function (err, req, res, next) {
//   console.error(err);
//   res.status(500).send('Internal Serverless Error');
// });
// app.use(express.static("public"))
// app.binaryTypes = ['*/*'];
// 设置模板引擎

app.get('/test', (req, res) => {
  res.render('test', { title: '我是标题' });
})

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');

module.exports = app;
